package com.infocollect.project.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.infocollect.project.api.entity.TappActinsEntity;
import com.infocollect.project.api.mapper.TappActinsMapper;
import com.infocollect.project.api.service.ITappActinsService;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * (TappActins)表服务实现类
 *
 * @author makejava
 * @since 2019-12-25 10:32:28
 */
@Service
public class TappActinsServiceImpl extends ServiceImpl<TappActinsMapper, TappActinsEntity> implements ITappActinsService {


    /**
     * 通过ID查询单条数据
     *
     * @param fid 主键
     * @return 实例对象
     */
    @Override
    public TappActinsEntity queryById(Long fid) {
        return this.baseMapper.selectById(fid);
    }



    /**
     * 新增数据
     *
     * @param tappActins 实例对象
     * @return 实例对象
     */
    @Override
    public TappActinsEntity insert(TappActinsEntity tappActins) {
        this.baseMapper.insert(tappActins);
        return tappActins;
    }

    /**
     * 修改数据
     *
     * @param tappActins 实例对象
     * @return 实例对象
     */
    @Override
    public TappActinsEntity update(TappActinsEntity tappActins) {
        this.baseMapper.updateById(tappActins);
        return this.queryById(tappActins.getFid());
    }
    /**
     * 获取待办的节点实例ID
     *
     * @param  processinsid 实例ID
     * @return 实例对象
     */
    @Override
    public TappActinsEntity queryTodoActins(@Param("processinsid") Long processinsid){
        return   this.baseMapper.queryTodoActins(processinsid);
    }
    /**
     * 通过主键删除数据
     *
     * @param fid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long fid) {
        return this.baseMapper.deleteById(fid) > 0;
    }
    @Override
    public     List<TappActinsEntity> GetNotHandleActIns(long procinsid,long factid){
        QueryWrapper<TappActinsEntity> queryWrapper=new QueryWrapper();
        queryWrapper.eq("fprocessinsid",procinsid).eq("fstatus",1).eq("factid",factid);
        return baseMapper.selectList(queryWrapper);
    }
    /**
     * 查询多条数据
     * @menu 根据实体对象是否有值 进行查询
     * @return 对象列表
     */
    @Override
    public List<TappActinsEntity> queryAll(TappActinsEntity entity){
        return this.baseMapper.queryAll(entity) ;
    }

    /**
     * 根据流程实例ID 获取当前走过的节点
     * @param fprocessinsid
     * @return
     * @return
     */
    @Override
    public  List<TappActinsEntity> getCompletedNodeList( Long fprocessinsid){
        QueryWrapper<TappActinsEntity> queryWrapper=new QueryWrapper<TappActinsEntity>();
        queryWrapper.eq("Fprocessinsid",fprocessinsid);
        queryWrapper.eq("fstatus",2);
        return this.baseMapper.selectList(queryWrapper) ;
    }

    /**
     * 获取所有当前节点对应的节点实例集合  根据到达时间相同 代表是同一次审批的
     */

    @Override
    public List<TappActinsEntity> GetAllCurrentActIns(Date arrivalDate, long procinsid, Long factid){
        QueryWrapper<TappActinsEntity> queryWrapper=new QueryWrapper();
        queryWrapper.eq("fprocessinsid",procinsid).eq("factid",factid).eq("farrivaldate",arrivalDate);
        return baseMapper.selectList(queryWrapper);
    }

    /**
     * 获取当前未处理 会签的节点实例集合
     * @param arrivalDate
     * @param procinsid
     * @param factid
     * @return
     */
    public  List<TappActinsEntity> GetNotHandleCountersignActIns(Date arrivalDate,long procinsid,Long factid){
        QueryWrapper<TappActinsEntity> queryWrapper=new QueryWrapper();
        queryWrapper.eq("fprocessinsid",procinsid).eq("fstatus",-1).eq("factid",factid).eq("farrivaldate",arrivalDate).orderByAsc("fcreationdate");
        return baseMapper.selectList(queryWrapper);
    }
}
